package com.ihr360.commons.lang;

import org.springframework.util.Assert;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public abstract class Ihr360ClassUtils {
    /**
     * 获取类的泛型Class 定义信息
     * @param clazz
     * @param argumentIndex
     * @return
     */
    public static Class getGenericSuperClassActualTypeArgument(Class clazz,int argumentIndex){
        Class trueClass;
        try {
            ParameterizedType genericSuperclass = (ParameterizedType) clazz.getGenericSuperclass();
            Type[] actualTypeArguments = genericSuperclass.getActualTypeArguments();
            Assert.isTrue(argumentIndex<actualTypeArguments.length,"argumentIndex greater than argument length");
            Type tType = actualTypeArguments[argumentIndex];
            trueClass = (Class) tType;
            return trueClass;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}